package cn.tedu._05weibo.config;

import cn.tedu._05weibo.intercepters.MyInterceptor;
import cn.tedu._05weibo.intercepters.MyInterceptor2;
import cn.tedu._05weibo.intercepters.UserLoginIntercepter;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

// 要记住配置类都要添加 @Configuration 注解
@Configuration
public class MvcConfig implements WebMvcConfigurer {
    @Override
    public void addInterceptors(InterceptorRegistry registry) {
//        1.拦截所有请求进行检查
//        registry.addInterceptor(new MyInterceptor());

//        2.拦截微博模块的所有请求
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/weibo/**");

//        3.拦截评论模块除了一个方法的全部请求
//        registry.addInterceptor(new MyInterceptor())
//                .addPathPatterns("/v1/comment/**")
//                .excludePathPatterns("/v1/comment/selectByWeiboId");

//        处理用户登录请求(评论模块和微博模块)
//        registry.addInterceptor(new UserLoginIntercepter())
//                .addPathPatterns("/v1/weibo/insert", "/v1/comment/insert");

        registry.addInterceptor(new MyInterceptor());
        registry.addInterceptor(new MyInterceptor2());
    }
}
